let validate = {};
import { phone, idCard } from "@/util/reg";

validate.install = Vue => {
  Vue.prototype.$vd = {
    phone: (rule, value, callback) => {
      if (!phone(value)) {
        callback(new Error("请输入正确的手机号"));
      }
      callback();
    },
    // 手机号选填
    phone_optional: (rule, value, callback) => {
      if (value) {
        if (!phone(value)) {
          callback(new Error("请输入正确的手机号"));
        }
        callback();
      } else {
        callback();
      }
    },
    idCard: (rule, value, callback) => {
      if (!idCard(value)) {
        callback(new Error("请输入正确的身份证号"));
      }
      callback();
    },
    passWord: (rule, value, callback) => {
      if (!value || value.length < 8) {
        callback(new Error("密码不少于八位"));
      }
      callback();
    }
  };
};

export default validate;
